package com.xiaoshuidi.cloud.module.rooms.controller.admin.roomequipmentcategory;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.roomequipmentcategory.vo.*;
import com.xiaoshuidi.cloud.module.rooms.convert.equipmentcategory.EquipmentCategoryConvert;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.pojo.EquipmentCategory;
import com.xiaoshuidi.cloud.module.rooms.service.IRoomEquipmentCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import java.util.List;
import java.util.Map;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

/**
 *  资产管理-资产类别
 *
 * @author Link
 * @since 2023-05-18
 */
@Tag(name = "管理后台 - 资产类别")
@RestController
@RequestMapping(ApiConstants.NAME + "/roomequipmentcategory")
@RequiredArgsConstructor
public class RoomEquipmentCategoryController {

    @Resource
    private IRoomEquipmentCategoryService iRoomEquipmentCategoryService;

    /**
     * 分页查询
     **/
    @Operation(summary = "资产类别-分页查询")
    @GetMapping("/pageQuery")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:query')")
    public CommonResult<PageResult<EquipmentCategoryPageResp>> pageQuery(EquipmentCategoryPageReqVO reqVO){
        PageResult<EquipmentCategoryPageResp> list = iRoomEquipmentCategoryService.pageQuery(reqVO);
        return success(list);
    }

    @Operation(summary = "资产类别列表")
    @GetMapping("/list")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:query')")
    public CommonResult<List<EquipmentCategoryPageResp>> pageQuery(){
        List<EquipmentCategoryPageResp> list = iRoomEquipmentCategoryService.listRecords();
        return success(list);
    }
    /**
     * 创建资产类别
     **/
    @PostMapping("/create")
    @Operation(summary = "创建资产类别")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:create')")
    public CommonResult<Long> createEquipmentCategory(@RequestBody EquipmentCategoryCreateReqVo createReqVO) {
        return success(iRoomEquipmentCategoryService.createEquipmentCategory(createReqVO));
    }
    /**
     * 更新资产类别
     **/
    @PutMapping("/update")
    @Operation(summary = "更新资产类别")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:update')")
    public CommonResult<Boolean> updateEquipmentCategory(@RequestBody EquipmentCategoryUpdateReqVo updateReqVO) {
        iRoomEquipmentCategoryService.updateEquipmentCategory(updateReqVO);
        return success(true);
    }
    /**
     * 删除资产类别
     **/
    @DeleteMapping("/delete")
    @Operation(summary = "删除资产类别")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:delete')")
    public CommonResult<Boolean> deleteEquipmentCategory(@RequestParam("id") Long id) {
        iRoomEquipmentCategoryService.deleteEquipmentCategory(id);
        return success(true);
    }
    /**
     * 获得资产类别
     **/
    @GetMapping("/get")
    @Operation(summary = "获得资产类别")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:query')")
    public CommonResult<EquipmentCategoryRespVO> getEquipmentCategory(@RequestParam("id") Long id) {
        EquipmentCategory ret = iRoomEquipmentCategoryService.getEquipmentCategory(id);
        return success(EquipmentCategoryConvert.INSTANCE.convert(ret));
    }
    /**
     * 获得资产树形列表
     **/
    @GetMapping("/getTreeList")
    @Operation(summary = "获得资产树形列表")
    @Parameter(name = "parentId", description = "上级ID")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:query')")
    public CommonResult<List<EquipmentCategoryTreeResp>> getTreeList(Long parentId) {
        List<EquipmentCategoryTreeResp> ret = iRoomEquipmentCategoryService.getTreeList(parentId);
        return success(ret);
    }
    /**
     * 获得资产类别-新增资产用
     **/
    @GetMapping("/getZcList")
    @Operation(summary = "获得资产树形列表")
    @PreAuthorize("@ss.hasAnyPermissions('rooms:equipment:category:query')")
    public CommonResult<List<Map<String,Object>>> getZcList() {
        List<Map<String,Object>> mapList = iRoomEquipmentCategoryService.getZcList();
        return success(mapList);
    }
}
